//
//  ChargeViewController.m
//  AntsExpress
//
//  Created by slccper on 16/1/12.
//  Copyright © 2016年 slccper. All rights reserved.
//

#import "ChargeViewController.h"
#import "clsOtherFun.h"
#import "clsBranch.h"
#import "AntsPickView.h"
@interface ChargeViewController ()
{
    NSMutableArray *list;
    NSString *bid;
    AntsPickView *Pickview;
}
@property (weak, nonatomic) IBOutlet UITextField *chang;
@property (weak, nonatomic) IBOutlet UITextField *kuan;
@property (weak, nonatomic) IBOutlet UITextField *gao;
@property (weak, nonatomic) IBOutlet UIWebView *WebView;
@property (weak, nonatomic) IBOutlet UITextField *Weight;
@property (weak, nonatomic) IBOutlet UILabel *memberno;
@property (weak, nonatomic) IBOutlet UILabel *membername;
@property (weak, nonatomic) IBOutlet UILabel *Money;
@property (weak, nonatomic) IBOutlet UIButton *address;

@end

@implementation ChargeViewController
-(void)awakeFromNib
{
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"如何收費";
    [_WebView setScalesPageToFit:YES];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"MathMoney" ofType:@"html"];
    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    [_WebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
    _WebView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    if ([[clsOtherFun getMemberId] integerValue]!=0) {
        self.memberno.text = [NSString stringWithFormat:@"會員編號：%ld",(long)[[clsOtherFun getMemberId] integerValue]+600000];
    }else{
        self.memberno.text = [NSString stringWithFormat:@"會員編號："];
    }
    UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 25)];
    
    [self.address setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 0, -10)];
//    self.memberno.text =[NSString stringWithFormat:@"%@%ld",@"會員編號：",[[clsOtherFun getMemberId]integerValue]];
    self.membername.text = [NSString stringWithFormat:@"%@%@",@"收件人：",[clsOtherFun getName]];
    
    // Do any additional setup after loading the view from its nib.
}
-(void)getWebData
{
    ants = [[clsAntsService alloc]init];
    ants.delegate =self;
    [ants GetBranchLists:@"1" action:^(NSDictionary *dic) {
        list = [clsBranch GetDataByArr:[dic objectForKey:@"data"]];
        if (list.count>0) {
            clsBranch *branch = list[0];
            [self.address setTitle:branch.BranchName forState:UIControlStateNormal];
            bid = branch.BranchID;
        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)MathMoney:(id)sender {
    NSString *chang = self.chang.text;
    if ([chang isEqualToString:@""]||chang==nil) {
        [clsOtherFun ShowMsg:@"請輸入長"];
        [self.chang becomeFirstResponder];
        return;
    }
    NSString *kuan = self.kuan.text;
    if ([kuan isEqualToString:@""]||kuan==nil) {
        [clsOtherFun ShowMsg:@"請輸入寬"];
        [self.kuan becomeFirstResponder];
        return;
    }
    NSString *gao = self.gao.text;
    if ([gao isEqualToString:@""]||gao==nil) {
        [clsOtherFun ShowMsg:@"請輸入高"];
        [self.gao becomeFirstResponder];
        return;
    }
    NSString *Weight = self.Weight.text;
    if ([Weight isEqualToString:@""]||Weight==nil) {
        [clsOtherFun ShowMsg:@"請輸入重量"];
        [self.Weight becomeFirstResponder];
        return;
    }
    [clsOtherFun showLoadingView:@"正在獲取數據..."];
    [ants MathExpress:chang :kuan :gao :Weight :bid];
}
-(void)getAntsDataSuccess:(NSInteger)type :(NSMutableDictionary *)pDictionary
{
    [clsOtherFun hideLoadingView];
    NSDictionary *dic = [pDictionary objectForKey:@"data"];
    NSString *status = [dic objectForKey:@"status"];
    if ([status integerValue]==200) {
        self.Money.text = [NSString stringWithFormat:@"%ld元",[[dic objectForKey:@"data"] integerValue]];
    }else{
        [clsOtherFun ShowMsg:[dic objectForKey:@"message"]];
    }
}
- (IBAction)AddressAction:(id)sender {
    if (list.count>0) {
        NSArray *arr = [clsBranch GetTitleByArr:list];
        Pickview = [[AntsPickView alloc]initPickviewWithArray:arr];
        [Pickview show:^(NSString *pSelectData,NSInteger select) {
            if(![pSelectData isEqualToString:@""])
            {
                clsBranch *branch = list[select];
                [self.address setTitle:branch.BranchName forState:UIControlStateNormal];
                bid = branch.BranchID;
            }
        }];
    }else{
        [clsOtherFun ShowMsg:@"暫無數據！"];
    }
    
}
@end
